<template>
  <div class="app-container">
    <el-card class="mb-20" v-for="(item, index) in dataSource" :key="index">
      <title-line :title="item.title" :styleObj="styleObj">
        <el-button type="primary" @click="saveFormData(item.code)"> 保存 </el-button>
      </title-line>
      <tinymce v-model="formData[item.code]" />
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'AgreementSet',
  data() {
    return {
      formData: {
        privacy: '',
        reg: '',
        business_certification: ''
      },
      dataSource: [],
      loading: true
    }
  },
  computed: {
    styleObj() {
      return {
        justifyContent: 'space-between'
      }
    }
  },
  watch: {},
  created() {
    this.getSet()
  },
  mounted() {},
  methods: {
    // 获取协议列表
    async getSet() {
      const { data } = await this.$http.system.tcp.getAgreementList()
      this.dataSource = data
      this.dataSource = data.map((item, index) => {
        for (const key in this.formData) {
          if (item.code === key) {
            this.formData[key] = data[index].content
          }
        }
        return item
      })
    },
    // 保存
    async saveFormData(code) {
      const { status, msg } = await this.$http.system.tcp.update({
        code,
        content: this.formData[code]
      })
      if (status === 200) {
        this.$message.success('修改成功')
        this.getSet()
      } else {
        this.$message.error(msg)
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
